package dk.au.cs.bdsi.sms.domain;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

import dk.au.cs.bdsi.sms.representation.Representation;


@XmlRootElement(name = "number", namespace = Representation.NAMESPACE)
public class PhoneNumber {
	private Integer countryCode;
	private Integer number;
	
	PhoneNumber() {/* For JAXB */}

	/**
	 * @param countryCode
	 * @param number
	 */
	public PhoneNumber(Integer countryCode, Integer number) {
		this.countryCode = countryCode;
		this.number = number;
	}

	/**
	 * @return the countryCode
	 */
	@XmlAttribute(name = "countryCode", required = false)
	public Integer getCountryCode() {
		return countryCode;
	}

	/**
	 * @param countryCode the countryCode to set
	 */
	public void setCountryCode(Integer countryCode) {
		this.countryCode = countryCode;
	}

	/**
	 * @return the number
	 */
	@XmlAttribute(name = "number", required = true)
	public Integer getNumber() {
		return number;
	}

	/**
	 * @param number the number to set
	 */
	public void setNumber(Integer number) {
		this.number = number;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((countryCode == null) ? 0 : countryCode.hashCode());
		result = prime * result + ((number == null) ? 0 : number.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof PhoneNumber))
			return false;
		PhoneNumber other = (PhoneNumber) obj;
		if (countryCode == null) {
			if (other.countryCode != null)
				return false;
		} else if (!countryCode.equals(other.countryCode))
			return false;
		if (number == null) {
			if (other.number != null)
				return false;
		} else if (!number.equals(other.number))
			return false;
		return true;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("PhoneNumber [countryCode=");
		builder.append(countryCode);
		builder.append(", number=");
		builder.append(number);
		builder.append("]");
		return builder.toString();
	}
}
